// pages/sigin/sigin.ts
import Notify from '@vant/weapp/notify/notify';
import { Request,Groups } from '../../utils/util'
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        navBarData: { // 导航栏的数据
            title: '注册',
            scan: false,
            navigateBack: true
        },
        name: '',
        card: '',
        pass: '',
        repass: '',
        uid: '',
        email: '',
        group: 0,
        groups: Groups,
        loading:true
    },

    signin() {
        if (this.data.name == '') {
            Notify({
                color: '#ffffff',
                background: app.globalData.notifyColor,
                message: '名字都忘啦？＞︿＜',
                top: app.globalData.navBarHeight
            });
        } else if (this.data.card == '') {
            Notify({
                color: '#ffffff',
                background: app.globalData.notifyColor,
                message: '一卡通一卡通！＞︿＜',
                top: app.globalData.navBarHeight
            });
        } else if (this.data.pass == '') {
            Notify({
                color: '#ffffff',
                background: app.globalData.notifyColor,
                message: '填个密码呀？＞︿＜',
                top: app.globalData.navBarHeight
            });
        } else if (this.data.uid == '') {
            Notify({
                color: '#ffffff',
                background: app.globalData.notifyColor,
                message: '留下你的UID！＞︿＜',
                top: app.globalData.navBarHeight
            });
        } else if (this.data.email == '') {
            Notify({
                color: '#ffffff',
                background: app.globalData.notifyColor,
                message: '请填写邮箱，用于密码找回',
                top: app.globalData.navBarHeight
            });
        } else if (this.data.pass != this.data.repass) {
            Notify({
                color: '#ffffff',
                background: app.globalData.notifyColor,
                message: '怎么搞得，两次密码不一样＞︿＜',
                top: app.globalData.navBarHeight
            });
        } else {
            wx.showLoading({
                title: '注册中...',
            })

            Request({
                url: '/signin',
                method: 'POST',
                data: {
                    form:{
                        card: this.data.card,
                        password: this.data.card,
                        name: this.data.card,
                        group: this.data.groups[this.data.group],
                        uid: this.data.card,
                        email: this.data.card,
                        studentnum: ''
                    }
                }
            }).then(res => {
                wx.hideLoading();
                Notify({
                    color: '#ffffff',
                    background: app.globalData.notifyColor,
                    message: res.msg,
                    top: app.globalData.navBarHeight
                });
                setTimeout(function () {
                    wx.reLaunch({
                        url: '/pages/index/index'
                    });
                  }, 2000)
            }).catch(error => {
                console.log(error);
                wx.hideLoading()
            });
        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady(){
        this.setData({loading:false})
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})